﻿using EF_Brave.Domain.bll_i;
using EF_Brave.Domain.Service;
using EF_Brave.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace EF_Brave.Domain.bll
{
    public class UserManage : RepositoryBase<Sys_User>, IUserManage
    {


        /// <summary>
        /// 管理用户登录验证
        /// add yuangang by 2016-05-12
        /// </summary>
        /// <param name="useraccount">用户名</param>
        /// <param name="password">加密密码（AES）</param>
        /// <returns></returns>
        public Sys_User UserLogin(string useraccount, string password)
        {
            var entity = this.Get(p => p.UserName == useraccount);

            //因为我们用的是AES的动态加密算法，也就是没有统一的密钥，那么两次同样字符串的加密结果是不一样的，所以这里要通过解密来匹配
            //而不能通过再次加密输入的密码来匹配
            //if (entity != null && new Common.CryptHelper.AESCrypt().Decrypt(entity.Password) == password)
            //{
            //    return entity;
            //}
            if (entity != null && entity.PassWord == password)
            {
                return entity;
            }
            return null;
        }


        public bool IsAdmin(int userId)
        {
            throw new NotImplementedException();
        }

        public string GetUserName(int userId)
        {
            throw new NotImplementedException();
        }

        public string GetUserDptName(int id)
        {
            throw new NotImplementedException();
        }

        public bool Remove(int userId)
        {
            throw new NotImplementedException();
        }


        public List<Sys_User> GetAll()
        {
            var list = this.LoadAll(null);
            if (list.Any())
            {
                
            }
            return list.ToList();
        }
    }
}
